$def with (work, edition, link_markup, id, class_list='')
$# :param Work work: The work that is referenced by this modal
$# :param Edition edition: The edition that is referenced by this modal
$# :param str link_markup: Markup for element that triggers book notes modal
$# :param str id: Unique identifier for this modal
$# :param str class_list: HTML classes for this component

$ username = ctx.user and ctx.user.key.split('/')[-1]
$ notes = work.get_users_notes(username, edition.key.split('/')[-1])
$ work_key = work.key

$if notes and len(notes.notes) > 0:
  $ display_delete_button = True
$else:
  $ display_delete_button = False

$ context = {
  $ "id": id
  $ }

<div class="$class_list">
  $:link_markup

  <div class="hidden">
    <div id="$id-metadata-form" class="floaterAdd metadata-form" data-context="$json_encode(context)">
      <div class="floaterHead">
        <h2>$_("My Book Notes")</h2>
        <a class="dialog--close">&times;<span class="shift">$_("Close")</span></a>
      </div>
      <form class="book-notes-form" method="POST" action="$(work.key)/notes.json">
        <p>$_("My private notes about this edition:")</p>
        <div>
          <textarea class="notes-modal-textarea" name="notes" rows="10">$(notes.notes if notes else "")</textarea>
        </div>
        <input type="hidden" name="work_id" value="$work_key.split('/')[-1]" />
        <input type="hidden" name="edition_id" value="$edition.key.split('/')[-1]" />
        <div class="note-form-buttons">
          <button class="delete-note-button cta-btn cta-btn--delete $('' if display_delete_button else 'hidden')" type="button">$_("Delete Note")</button>
          <button class="update-note-button cta-btn cta-btn--shell">$_("Save Note")</button>
        </div>
      </form>
    </div>
  </div>
</div>
